﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace HomeWork6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonSelect_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = true;
            fileDialog.Title = "请选择两个文本文件";
            fileDialog.Filter = "文本文件(*.txt)|*.txt";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string file1 = fileDialog.FileNames[0];
                string file2 = fileDialog.FileNames[1];
                MessageBox.Show("已选择文件:" + file1 + "\n" + file2, "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                FileStream file_1 = new FileStream(file1,FileMode.Open,FileAccess.Read);
                FileStream file_2 = new FileStream(file2, FileMode.Open, FileAccess.Read);
                FileStream fileAdd = new FileStream("Z:\\Documents\\代码\\C#作业\\HomeWork6\\Data\\FileAdd", FileMode.Create, FileAccess.Write);
                //在虚拟机里跑的，所以路径有点奇怪
                StreamReader reader1 = new StreamReader(file_1, System.Text.Encoding.Default);
                StreamReader reader2 = new StreamReader(file_2, System.Text.Encoding.Default);
                StreamWriter writer = new StreamWriter(fileAdd, System.Text.Encoding.Default);
                int count1 = 0;
                int count2 = 0;
                for (string s = reader1.ReadLine(); s != null; s = reader1.ReadLine()) {
                    count1++;
                    writer.WriteLine(s);
                }
                for (string s = reader2.ReadLine(); s != null; s = reader2.ReadLine())
                {
                    count2++;
                    writer.WriteLine(s);
                }
                reader1.Close();
                reader1.Close();
                writer.Close();
            }
        
        }
    }
}
